/*
 * Copyright (c) 2008, 2016, OneAPM and/or its affiliates. All rights reserved.
 */
package me.yufan.chess.modle;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Title: Board
 * Description: 五子棋基础棋盘对象, 存储内容为棋盘信息和棋子
 *
 * @author Yufan
 * @version 1.0.0
 * @since 2016-01-26 14:51
 */
public class Board {

    private static final Logger LOGGER = LoggerFactory.getLogger(Board.class);
    private Chessman[][] boardPlate;

    /**
     * 初始化棋盘
     *
     * @param size 棋盘尺寸
     */
    public Board(int size) {
        boardPlate = new Chessman[size][size];
    }

    /**
     * 下棋方法
     *
     * @param xPosition 横轴位置 1 ~ 棋盘大小
     * @param yPosition 纵轴位置 1 ~ 棋盘大小
     * @param chess     棋子对象
     */
    public void playChess(int xPosition, int yPosition, Chessman chess) {
        if (boardPlate == null) {
            throw new IllegalStateException("棋盘未初始化");
        }
        try {
            boardPlate[xPosition - 1][yPosition -1] = chess;
        } catch (ArrayIndexOutOfBoundsException e) {
            LOGGER.info("", e);
            throw new IllegalArgumentException("下棋位置不存在");
        }
    }

    /**
     * 获取五子棋棋盘, 用于打印或者判断输赢
     *
     * @return <code>Chessman[][]</code>
     */
    public Chessman[][] getBoardPlate() {
        return boardPlate;
    }
}
